package backTracking;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

//77. 组合
public class Num77_combine {
    List<List<Integer>> result = new ArrayList<>();
    LinkedList<Integer> path = new LinkedList<>();
    public List<List<Integer>> combine(int n, int k) {
        combineHelper(n , k , 1);
        return result;

    }
    public void combineHelper(int n , int k , int startIndex){
        //终止条件
        if (path.size() == k){
            result.add(new ArrayList<>());
            return ;
        }
        for (int i = startIndex; i <= n; i++) {
            path.add(i);
            combineHelper(n , k , i + 1);
            path.removeLast();
        }
    }
}
